function [ res ] = EP( times, data, freq, bins )
%EP (Epoch Folding) generates profile from 'times' and 'data' for known 
%   'freq' - frequency. 
    times=mod(times,1/freq)*freq;
    times=gather(times);
    data=gather(data);
    res=zeros(bins,2);
    for i=1:bins
        temp=times<i/bins & times>(i-1)/bins;
        [a,b,c]=normfit(data(temp));
        res(i,1)=a;
        res(i,2)=abs(c(2)-c(1)/2);
        res(i,2)=mean(abs(data(temp)))/sqrt(sum(temp))/2;
        res(i,2)=std(data(temp))/sqrt(sum(temp))/2;
    end
end

